package com.sensoro.factoryconfig.util;

import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

import javax.crypto.Mac;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;

import com.sensoro.factoryconfig.constans.Constans;

public class Utils {

	public static byte[] getSignature(byte[] data, String baseKey) {
		Mac shaMac;
		byte[] secretBytes = baseKey.getBytes();
		byte[] signatureBytes = null;
		try {
			shaMac = Mac.getInstance(Constans.ENCODE);
			SecretKey secretKey = new SecretKeySpec(secretBytes,
					Constans.ENCODE);
			shaMac.init(secretKey);
			signatureBytes = shaMac.doFinal(data);
		} catch (InvalidKeyException e) {
			e.printStackTrace();
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}

		return signatureBytes;
	}
}
